package com.yyq.gxdc.config;

import com.yyq.gxdc.interceptor.LoginHandlerInterceptor;
import com.yyq.gxdc.interceptor.UserLoginHandlerInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    //所有的WebMvcConfigurerAdapter组件都会一起起作用
    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        WebMvcConfigurer.super.addInterceptors(registry);
//        // addPathPatterns 用于添加拦截规则
//        // excludePathPatterns 用户排除拦截
//        LoginHandlerInterceptor loginInterceptor = new LoginHandlerInterceptor();
//        //静态资源； *.css,*.js
//        //SpringBoot已经做好了静态资源映射
////                registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
////                .excludePathPatterns("/index.html","/","/user/login","/static/**","/webjars/**");
//        // /**  表示拦截所有路径下的所有请求
//        registry.addInterceptor(loginInterceptor)
//                .addPathPatterns("/gxdc/**").excludePathPatterns("/gxdc/login.html","/gxdc/login","/gxdc/css/**","/gxdc/fonts/**","/gxdc/imgs/**","/gxdc/js/**");

//        // 注册admin拦截器
        LoginHandlerInterceptor loginInterceptor = new LoginHandlerInterceptor();
        InterceptorRegistration loginRegistry = registry.addInterceptor(loginInterceptor);
//        //拦截地址
        loginRegistry.addPathPatterns("/mgr/index.html");
        loginRegistry.addPathPatterns("/gxdc/admin/**");
        //放开地址
        loginRegistry.excludePathPatterns("/gxdc/css/*.css");
        loginRegistry.excludePathPatterns("/gxdc/fonts/*.fonts");
        loginRegistry.excludePathPatterns("/gxdc/img/**");
        loginRegistry.excludePathPatterns("/gxdc/js/*.js");
        loginRegistry.excludePathPatterns("/gxdc/upload/**");
        loginRegistry.excludePathPatterns("/gxdc/admin/login.html");
        loginRegistry.excludePathPatterns("/gxdc/admin/adminlogin");

        // 注册user拦截器
        UserLoginHandlerInterceptor userLoginHandlerInterceptor = new UserLoginHandlerInterceptor();
        InterceptorRegistration loginRegistry1 = registry.addInterceptor(userLoginHandlerInterceptor);
        //拦截地址
        loginRegistry1.addPathPatterns("/gxdc/**");

        //放开地址
        loginRegistry1.excludePathPatterns("/gxdc/css/*.css");
        loginRegistry1.excludePathPatterns("/gxdc/fonts/*.fonts");
        loginRegistry1.excludePathPatterns("/gxdc/img/**");
        loginRegistry1.excludePathPatterns("/gxdc/js/*.js");
        loginRegistry1.excludePathPatterns("/gxdc/upload/**");
        loginRegistry1.excludePathPatterns("/gxdc/login.html");
        loginRegistry1.excludePathPatterns("/gxdc/login");
//        loginRegistry1.excludePathPatterns("/gxdc/session");
        loginRegistry1.excludePathPatterns("/gxdc/register.html");
        loginRegistry1.excludePathPatterns("/gxdc/register");
        loginRegistry1.excludePathPatterns("/gxdc/index.html");
        loginRegistry1.excludePathPatterns("/gxdc/left.html");
        loginRegistry1.excludePathPatterns("/gxdc/right.html");
        loginRegistry1.excludePathPatterns("/gxdc/fenlei.html");
        loginRegistry1.excludePathPatterns("/gxdc/comment/findPage");
        loginRegistry1.excludePathPatterns("/gxdc/classIfication/findlist");
        loginRegistry1.excludePathPatterns("/gxdc/pictureRotation/finList");
        loginRegistry1.excludePathPatterns("/gxdc/essay/Page");
        loginRegistry1.excludePathPatterns("/gxdc/register");
        loginRegistry1.excludePathPatterns("/gxdc/admin/login.html");
        loginRegistry1.excludePathPatterns("/gxdc/admin/adminlogin");
        loginRegistry1.excludePathPatterns("/gxdc/repassword.html");
        loginRegistry1.excludePathPatterns("/gxdc/email/**");
}
}
